package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Score;
import cn.kgc.vue.service.ScoreService;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


@RestController
@RequestMapping("score")
@Api(tags = "成绩模块")
public class ScoreController {

    @Resource
    private ScoreService scoreService;

    @PostMapping("page")
    @ApiOperation("成绩分页")
    public ResponseResult page(@RequestBody QueryCondition<Score> queryCondition){
        return scoreService.scorePage(queryCondition);
    }

    @LogAnnotation(model="成绩模块",operation= OperationType.ADD)
    @PostMapping("saveUpdataScore")
    @ApiOperation("修改和新增")
    public ResponseResult saveUpdataScore(@RequestBody Score score){
        return scoreService.saveUpdataScore(score);
    }

    @LogAnnotation(model="成绩模块",operation= OperationType.DELETE)
    @RequiresPermissions("base:score:delete")
    @DeleteMapping("deleteScore/{id}")
    @ApiOperation("删除成绩")
    public ResponseResult deleteScore(@PathVariable Integer id){
          scoreService.removeById(id);
        return ResponseResult.success().message("删除成功");
    }


    @ApiOperation(value = "批量导入")
    @PostMapping("importScore")
    public ResponseResult importStudent( MultipartFile file) throws Exception {


        return scoreService.importStudent(file);
    }

    @PostMapping("exportScore")
    @ApiOperation("批量导出")
    public ResponseResult exportStudent(HttpServletResponse response, @RequestBody Map<String,Object> exportParam) throws Exception {
        return   scoreService.exportStudent(response,exportParam);
    }


    @GetMapping("dataVisual")
    @ApiOperation("数据可视化")
    public ResponseResult scoreDataVisual(){

        return scoreService.scoreDataVisual();

    }

}
